package 中等;

public class 数组中最大子数组的和 {
    public static void main(String[] args) {
        int[] arr = {-10,-20,-5,-3,-6,-4};
        System.out.println(getMaxSum(arr));

    }

    public static int getMaxSum(int[] arr){
        int max = arr[0];
        int sum = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (sum>0){
                sum += arr[i];
            }else {
                sum = arr[i];
            }
            max = Math.max(max,sum );
        }
        return max;

    }

}
